//
//  SYDHomeViewController.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/14.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDHomeViewController.h"
#import "SYDOutOfTheCar.h"
#import "SYDDownwindOrderView.h"
#import "YMTravelTrack.h"
#import "YMUILabel.h"
#import "YMTakePassengerViewController.h"
#import "YMWebSocket.h"
#import "YMUploadRealTimeTool.h"

static NSString *kRealTimer = @"kRealTimer";

@interface SYDHomeViewController ()

@property (nonatomic, strong) UIView *maskView;//遮罩View
@property (nonatomic, strong) SYDDownwindOrderView *downWindowOrderView;
@property(nonatomic,strong)SYDOutOfTheCar *outCarView;

//定时器----实时上传经纬度
@property(nonatomic,strong)NSTimer *timer;

//socket
@property(nonatomic,strong)SYDSRWebsocketManage *webSocket;
//进入首页获取到socket信息
@property(nonatomic,strong)NSDictionary *message;

//背景view
@property(nonatomic,strong)UIView *contentView;
//用户头像
@property(nonatomic,strong)UIImageView *userImageView;
@property(nonatomic,strong)UILabel *todayIncomeLbl;
@property(nonatomic,strong)UILabel *yuanLabel;

@property(nonatomic, strong) UILabel *orderTitleLb;
@property(nonatomic, strong) YMUILabel *orderLb;
@property(nonatomic, strong) UILabel *hourTitleLb;
@property(nonatomic, strong) YMUILabel *hourLb;
//曲线
@property(nonatomic,strong)UIImageView *curveImageView;

//接单成绩统计
@property(nonatomic,strong)statModel *statModel;
@property(nonatomic,strong)UILabel *moneyLabel;
@property(nonatomic,strong)NSString *amountStr;//收入
@property(nonatomic,strong)UILabel *todayOrderLabel;
@property(nonatomic,strong)NSString *ordersStr;//接单数量
@property(nonatomic,strong)UILabel *onLineTimeLbl;
@property(nonatomic,strong)NSString *timsStr;//在线时长

//用户审核状态
@property(nonatomic,assign) NSInteger statusType;
//用户审核状态  ---- 对应提示语
@property(nonatomic,strong) UIImageView *promptImage;
@property(nonatomic,strong) UILabel *promptLabel;//提示语

// 两种状态  出车/听车中
@property(nonatomic,strong) UIButton * goBtn;
@property(nonatomic,strong) UIButton * outBtn;//收车按钮

@property(nonatomic,assign) NSInteger driveContentStatus;//司机当前状态
//订单号
@property(nonatomic,strong) NSString *orderNo;

@property(nonatomic,strong) SendsingleModel *sendsingleModel;
@property(nonatomic,strong) SYDAccount *account;
@property(nonatomic, assign) YMOrderStatus orderStatus;
@property(nonatomic, assign) YMUserStatus userStatus;
@property(nonatomic, strong) YMOrder *order;

@end

@implementation SYDHomeViewController

- (void)setOrderStatus:(YMOrderStatus)orderStatus{
    _orderStatus = orderStatus;
    [YMOrderTool saveOrderStatus:orderStatus];
}

- (UILabel *)orderTitleLb{
    if (!_orderTitleLb) {
        _orderTitleLb = [[UILabel alloc] init];
        _orderTitleLb.textColor = [UIColor colorWithHexString:@"#b5f4c6"];
        _orderTitleLb.font = [UIFont systemFontOfSize:14];
        _orderTitleLb.text = @"今日接单";
        [self.contentView addSubview:_orderTitleLb];
    }
    return _orderTitleLb;
}

- (YMUILabel *)orderLb{
    if (!_orderLb) {
        _orderLb = [[YMUILabel alloc] init];
        _orderLb.textColor = [UIColor whiteColor];
        _orderLb.font = [UIFont systemFontOfSize:29];
        _orderLb.text = @"0单";
        [self.contentView addSubview:_orderLb];
    }
    return _orderLb;
}

- (UILabel *)hourTitleLb{
    if (!_hourTitleLb) {
        _hourTitleLb = [[UILabel alloc] init];
        _hourTitleLb.textColor = [UIColor colorWithHexString:@"#b5f4c6"];
        _hourTitleLb.font = [UIFont systemFontOfSize:14];
        _hourTitleLb.textAlignment = NSTextAlignmentRight;
        _hourTitleLb.text = @"在线时长";
        [self.contentView addSubview:_hourTitleLb];
    }
    return _hourTitleLb;
}

- (YMUILabel *)hourLb{
    if (!_hourLb) {
        _hourLb = [[YMUILabel alloc] init];
        _hourLb.textColor = [UIColor whiteColor];
        _hourLb.font = [UIFont systemFontOfSize:29];
        _hourLb.textAlignment = NSTextAlignmentRight;
        _hourLb.text = @"16.3时";
        [self.contentView addSubview:_hourLb];
    }
    return _hourLb;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (iPhone8_X) {
        NSLog(@"width:%f,height:%f",[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
    } else {
        NSLog(@"width:%f,height:%f",[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
    }
}

- (void)closeTimer{
    [_timer setFireDate:[NSDate distantFuture]];
    [self.timer invalidate];
    _timer = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CONTENT_BG_COLOR;
    self.navigationBar.title = @"首页";
    [self navigationBarHandle];
    
    [self initHomeUIView];
    [self initUI];
    
    //用户审核状态
    self.account = [SYDAccountTool getAccount];
    NSLog(@"%@",_account.invaildDate);
    self.statusType = [self.account.accountStatus integerValue];//[self.loginModel.accountStatus integerValue];
    self.orderNo = @"";
    
    self.userStatus = YMUserStatusVerfied;
    [self updateUserStatus];
    
    [self getHomeData];
//    [self getNearyOrder];
    
    [[YMWebSocket sharedInstance] connect];
    
    WEAKSELF
    [YMWebSocket sharedInstance].connectBlock = ^(YMWebSocketStatus status, id message) {
        switch (status) {
            case YMWebSocketStatusConnected:
            {
                NSLog(@"YMWebSocketStatusConnected");
                [[YMTimer sharedInstance] scheduledDispathTimerWithName:kRealTimer timeInterval:60.0 queue:nil repeats:YES action:^{
                    [YMUploadRealTimeTool send];
                }];
            }
                break;
            case YMWebSocketStatusFailed:
            {
                NSLog(@"YMWebSocketStatusFailed");
                [[YMTimer sharedInstance] cancelTimerWithName:kRealTimer];
            }
                break;
            case YMWebSocketStatusColosedByUser:
            {
                NSLog(@"YMWebSocketStatusColosedByUser");
                [[YMTimer sharedInstance] cancelTimerWithName:kRealTimer];
            }
                break;
            case YMWebSocketStatusColosedByServer:
            {
                NSLog(@"YMWebSocketStatusColosedByServer");
                [[YMTimer sharedInstance] cancelTimerWithName:kRealTimer];
            }
                break;
            case YMWebSocketStatusReceived:
            {
                NSLog(@"YMWebSocketStatusReceived");
                [weakSelf socketOrder:message];
            }
                break;
                
            default:
                break;
        }
    };
    
    self.outCarView.carBlock = ^{
        NSLog(@"去接乘客");
        YMTakePassengerViewController * takePassengerVC = [[YMTakePassengerViewController alloc] init];
        takePassengerVC.order = weakSelf.order;
        takePassengerVC.trvaleBlock = ^{
            YMOrderStatus status = [YMOrderTool getOrderStatus];
            if (status == YMOrderStatusTraving) {
                [weakSelf.outCarView setBtnTitle:@"行程中..."];
            }
            
            if (status == YMOrderStatusListen) {
                weakSelf.orderStatus = YMOrderStatusListen;
                [weakSelf updateOrderStatus];
            }
        };
        [weakSelf.navigationController pushViewController:takePassengerVC animated:YES];
    };
}

- (void)socketOrder:(id)message{
    id dic = [message mj_JSONObject];
    NSInteger type = [dic[@"type"] integerValue];
    switch (type) {
        case 1: // 用户状态
        {
            [self socketUserState:[dic[@"obj"] integerValue]];
        }
            break;
        case 2: // 实时信息
        {
        }
            break;
        case 3: // 派单
        {
            YMOrder * order = [YMOrder mj_objectWithKeyValues:dic[@"obj"]];
            self.order = order;
            [self showOrder];
        }
            break;
        case 4: // 派单结果反馈，接单or拒单
        {
        }
            break;
            
        default:
            break;
    }
}

- (void)socketUserState:(NSInteger)type{
    switch (type) {
        case 1:
        {
            self.orderStatus = YMOrderStatusNone;
        }
            break;
        case 2:
        {
            self.orderStatus = YMOrderStatusListen;
        }
            break;
            
        case 3:
        {
            self.orderStatus = YMOrderStatusListen;
        }
            break;
        case 4:
        {
            self.orderStatus = YMOrderStatusAccept;
            
            [self getNearyOrder];
        }
            break;
        case 5:
        {
            self.orderStatus = YMOrderStatusTraving;
            
            [self getNearyOrder];
        }
            break;
            
        default:
            break;
    }
    
    [self updateOrderStatus];
}


- (void)initUI{
    [self.orderTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@48);
        make.top.mas_equalTo(self.userImageView.mas_bottom).offset(30);
        make.width.equalTo(@100);
    }];
    
    [self.orderLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@48);
        make.top.mas_equalTo(self.orderTitleLb.mas_bottom).offset(10);
        make.width.equalTo(@100);
    }];
    
    [self.hourTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-48);
        make.top.mas_equalTo(self.userImageView.mas_bottom).offset(30);
        make.width.equalTo(@100);
    }];
    
    [self.hourLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-48);
        make.top.mas_equalTo(self.hourTitleLb.mas_bottom).offset(10);
        make.width.equalTo(@100);
    }];
}

- (void)initHomeUIView{
    
    CGFloat headerViewHeight;
    CGFloat userImageViewMas_Top;
    CGFloat userImageViewWidth;
    CGFloat moneyLabelMas_Top;
    CGFloat DriverStatusBtnMas_botton;
    CGFloat DriverStatusBtnWidth;
    CGFloat promptImageMas_botton;
    if (iphone4) {
        headerViewHeight = 266;
        userImageViewMas_Top  = 15;
        userImageViewWidth = 165;
        moneyLabelMas_Top = 10;
        DriverStatusBtnMas_botton = -15;
        DriverStatusBtnWidth = 70;
        promptImageMas_botton = -5;
        
    }else if (iPhone5_SE){
        headerViewHeight = 305;
        userImageViewMas_Top  = 25;
        userImageViewWidth = 169;
        moneyLabelMas_Top = 20;
        DriverStatusBtnMas_botton = -15;
        DriverStatusBtnWidth = 75;
        promptImageMas_botton = -5;
    }else {
        headerViewHeight = 355;
        userImageViewMas_Top  = 35;
        userImageViewWidth = 190;
        moneyLabelMas_Top = 30;
        DriverStatusBtnMas_botton = -30;
        DriverStatusBtnWidth = 100;
        promptImageMas_botton = -10;
    }
    
    self.contentView = [[UIView alloc]init];
    self.contentView.backgroundColor = GREEN_COLOR;
    [self.view addSubview:self.contentView];
    
    self.userImageView = [[UIImageView alloc]init];
    self.userImageView.image = [UIImage imageNamed:@"index_income_bj_y"];
    [self.contentView addSubview:self.userImageView];
    
    self.todayIncomeLbl = [[UILabel alloc]init];
    [self.contentView addSubview:self.todayIncomeLbl];
    self.todayIncomeLbl.text = @"今日收入";
    self.todayIncomeLbl.textAlignment = NSTextAlignmentCenter;
    self.todayIncomeLbl.textColor = SUB_TITLE_COLOR;
    self.todayIncomeLbl.font = [UIFont systemFontOfSize:14];
    
    self.moneyLabel = [[UILabel alloc]init];
    self.moneyLabel.text = self.amountStr;
    self.moneyLabel.text = @"0.00";
    self.moneyLabel.textAlignment = NSTextAlignmentCenter;
    self.moneyLabel.textColor = TITLE_COLOR;
    self.moneyLabel.font = [UIFont systemFontOfSize:36];
    [self.contentView addSubview:self.moneyLabel];
    
    self.yuanLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.yuanLabel];
    self.yuanLabel.text = @"元";
    self.yuanLabel.textAlignment = NSTextAlignmentCenter;
    self.yuanLabel.textColor = SUB_TITLE_COLOR;
    self.yuanLabel.font = [UIFont systemFontOfSize:14];
    
    
    /*  曲线 */
    self.curveImageView = [[UIImageView alloc]init];
    self.curveImageView.backgroundColor = GREEN_COLOR;
    self.curveImageView.image = [UIImage imageNamed:@"index_bj_qx"];
    [self.view addSubview:self.curveImageView];
    
    /*对用户的提示语*/
    self.promptImage = [[UIImageView alloc]init];
    self.promptImage.image = [UIImage imageNamed:@"icon_bomb_box_bj"];
    self.promptLabel = [[UILabel alloc]init];
    self.promptLabel.textAlignment = NSTextAlignmentCenter;
    self.promptLabel.textColor = TITLE_COLOR;
    self.promptLabel.font = [UIFont systemFontOfSize:12];
    self.promptLabel.numberOfLines = 0;
    self.promptLabel.text = @"您的车主身份 正在审核中\n请耐心等待，审核通过即可接单。";
    
    [self.view addSubview:self.promptImage];
    [self.promptImage addSubview:self.promptLabel];
    //出车/听车中
    self.goBtn = [[UIButton alloc]init];
    [self.goBtn setEnabled:NO];
    [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_out_disable"] forState:UIControlStateNormal];
    [self.goBtn addTarget:self action:@selector(goBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.goBtn];
    
    /*收车按钮*/
    self.outBtn = [[UIButton alloc]init];
    self.outBtn.hidden = YES;
    [self.outBtn setImage:[UIImage imageNamed:@"btn_bus_collect_default"] forState:UIControlStateNormal];
    [self.outBtn addTarget:self action:@selector(outBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.outBtn];
    if (iPhone8_X) {
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(0);
            make.top.equalTo(self.view.mas_top).offset(88);
            make.right.equalTo(self.view.mas_right).offset(0);
            make.height.equalTo(@(headerViewHeight));
        }];
    } else {
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(0);
            make.top.equalTo(self.view.mas_top).offset(64);
            make.right.equalTo(self.view.mas_right).offset(0);
            make.height.equalTo(@(headerViewHeight));
        }];
    }
    
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(userImageViewWidth));
        make.height.equalTo(@(userImageViewWidth));
        make.top.equalTo(self.contentView.mas_top).offset(userImageViewMas_Top);
        make.centerX.equalTo(self.contentView.mas_centerX);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.userImageView.mas_centerX);
        make.centerY.equalTo(self.userImageView.mas_centerY);
        make.height.equalTo(@(36));
    }];
    
    [self.todayIncomeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.userImageView.mas_centerX);
        make.bottom.equalTo(self.moneyLabel.mas_top).offset(-20);
        make.height.equalTo(@(14));
    }];
    
    [self.yuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.userImageView.mas_centerX);
        make.top.equalTo(self.moneyLabel.mas_bottom).offset(20);
        make.height.equalTo(@(14));
    }];
    
    [self.curveImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(0);
        make.top.equalTo(self.contentView.mas_bottom).offset(0);
        make.right.equalTo(self.view.mas_right).offset(0);
        make.height.equalTo(@(40));
    }];
    
    [self.goBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(DriverStatusBtnMas_botton);
        make.width.equalTo(@(DriverStatusBtnWidth));
        make.height.equalTo(@(DriverStatusBtnWidth));
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    [self.outBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.goBtn.mas_centerY);
        make.width.equalTo(@(DriverStatusBtnWidth * 0.7));
        make.height.equalTo(@(DriverStatusBtnWidth * 0.7));
        make.right.equalTo(self.view.mas_right).offset(-15);
    }];
    
    [self.promptImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.goBtn.mas_centerX);
        make.bottom.equalTo(self.goBtn.mas_top).offset(promptImageMas_botton);
        make.height.equalTo(@(60));
    }];
    [self.promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@0);
        make.right.mas_equalTo(@0);
        make.top.mas_equalTo(@0);
        make.bottom.mas_equalTo(@0);
    }];
    
    [self.view addSubview:self.outCarView];
    [self.outCarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(290));
        make.height.equalTo(@(64));
        make.centerX.equalTo(self.goBtn.mas_centerX);
        make.bottom.equalTo(self.goBtn.mas_top).offset(-10);
    }];
    
    self.outCarView.hidden = YES;
}

#pragma mark - 展示订单
- (void)showOrder{
    [self.maskView addSubview:self.downWindowOrderView];
    [self.view addSubview:self.maskView];
}

#pragma mark - 接单反馈
- (void)orderFeedBack{
    WEAKSELF
    self.downWindowOrderView.block = ^{
        NSLog(@"failure");
        [weakSelf.maskView removeAllSubviews];
        [weakSelf.maskView removeFromSuperview];
    };
    
    self.downWindowOrderView.agreeBlock = ^{
        NSLog(@"success");
        [weakSelf.maskView removeAllSubviews];
        [weakSelf.maskView removeFromSuperview];
        weakSelf.orderStatus = YMOrderStatusAccept;
        [weakSelf updateOrderStatus];
    };
}

#pragma mark - test
- (void)readData{
    NSDictionary * dic = [NSString resourcePathWithFileName:@"order.json"];
    if (dic) {
        self.order = [YMOrder mj_objectWithKeyValues:dic[@"obj"]];
        [self showOrder];
        self.downWindowOrderView.model = self.order;
    }
}

#pragma mark - 获取最近的一次订单
- (void)getNearyOrder{
    WEAKSELF
    [[SYDNetwork shareTool] getOrderSuccess:^(NSURLSessionDataTask *task, id responseObject) {
        @try{
            [YMAutoGenerateModelTool propertyWithDictionary:responseObject[@"obj"]];
            YMOrder * order = [YMOrder mj_objectWithKeyValues:responseObject[@"obj"]];
            weakSelf.order = order;
            [YMOrderTool saveOrderNo:order.matchId];
            [weakSelf updateOrderStatus];
        }
        @catch(NSException *e){
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

#pragma mark - 出车
- (void)goBtnAction:(UIButton *)sender{
    if (self.userStatus == YMUserStatusVerfied) {
        self.orderStatus = YMOrderStatusListen;
        [self updateOrderStatus];
    }
}

#pragma mark - 收车
- (void)outBtnAction:(UIButton *)sender{
    [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_out_default"] forState:UIControlStateNormal];
    [self.goBtn setEnabled:YES];
    sender.hidden = YES;
}

#pragma mark - 获取首页基础信息
- (void)getHomeData{
    [[SYDNetwork shareTool] getHomeTodayDataSuccess:^(NSURLSessionDataTask *task, id responseObject) {
        @try{
            YMHomeBase * model = [YMHomeBase mj_objectWithKeyValues:responseObject[@"obj"]];
            self.moneyLabel.text = [NSString stringWithFormat:@"%.2f", [model.sumOfRevenueDay floatValue]];
            self.orderLb.text = [NSString stringWithFormat:@"%ld单", [model.countOfOrdersDay integerValue]];
            self.hourLb.text = [NSString stringWithFormat:@"%.2f时", [model.hoursOnline floatValue]];
        }
        @catch(NSException *e){
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}

#pragma mark - 更新用户状态
- (void)updateUserStatus{
    NSString * promp = @"";
    NSString * subStr = @"";
    [self.goBtn setEnabled:NO];
    switch (self.userStatus) {
        case YMUserStatusVerifing:{
            self.outCarView.hidden = YES;
            self.promptImage.hidden = NO;
            promp = @"您的车主身份 正在审核中\n请耐心等待，审核通过即可接单。";
            subStr = @"正在审核中";
        }
            break;
        case YMUserStatusVerfied:{
            self.outCarView.hidden = YES;
            self.promptImage.hidden = YES;
            [_goBtn setImage:[UIImage imageNamed:@"btn_bus_out_default"] forState:UIControlStateNormal];
            [self.goBtn setEnabled:YES];
        }
            break;
        case YMUserStatusNone:{
            self.outCarView.hidden = YES;
            self.promptImage.hidden = NO;
            promp = @"您的车主身份 审核未通过\n很遗憾暂时无法接单。";
            subStr = @"审核未通过";
        }
            break;
        default:
            break;
    }
    self.promptLabel.text = promp;
    [self changeLabel:self.promptLabel subString:subStr];
}

#pragma mark - 更新订单状态
- (void)updateOrderStatus{
    [self.goBtn setEnabled:NO];
    self.outBtn.hidden = NO;
    self.outCarView.hidden = YES;
    self.outCarView.order = self.order;
    switch (self.orderStatus) {
        case YMOrderStatusListen:
        {
            self.promptImage.hidden = YES;
            [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_hear_default"] forState:UIControlStateNormal];
        }
            break;
        case YMOrderStatusAccept:
        {
            self.outCarView.hidden = NO;
            self.outBtn.hidden = YES;
            [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_out_ing_default"] forState:UIControlStateNormal];
        }
            break;
        case YMOrderStatusDenied:
        {
            [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_out_ing_default"] forState:UIControlStateNormal];
        }
            break;
        case YMOrderStatusTraving:
        {
            self.outCarView.hidden = NO;
            [self.outCarView setBtnTitle:@"行程中..."];
            self.outBtn.hidden = YES;
            [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_out_ing_default"] forState:UIControlStateNormal];
        }
            break;
        case YMOrderStatusNone:
        {
            self.outBtn.hidden = YES;
            [self.goBtn setEnabled:YES];
            [self.goBtn setImage:[UIImage imageNamed:@"btn_bus_out_default"] forState:UIControlStateNormal];
        }
        default:
            break;
    }
}

#pragma mark - 导航栏
- (void)navigationBarHandle{
    
    WEAKSELF
    [self leftNavButtonWithImage:[UIImage imageNamed:@"nav_button_personal_center"] action:^{
        SYDMineViewController *mineVc = [[SYDMineViewController alloc]init];
        [weakSelf.navigationController pushViewController:mineVc animated:YES];
    }];
    
    [self rightNavButtonWithImage:[UIImage imageNamed:@"nav_button_index_news"] action:^{
        [weakSelf.navigationController pushViewController:[[SYDMessageViewController alloc]init] animated:YES];
    }];
}

#pragma mark - 富文本操作
-(void) changeLabel:(UILabel *)label subString:(NSString *)subString
{
    NSRange range = [label.text rangeOfString:subString];
    
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attrString addAttribute:NSForegroundColorAttributeName value:GREEN_COLOR range:range];
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:range];
    
    attrString.lineSpacing = 5.0;
    
    label.attributedText = attrString;
    
    label.textAlignment = NSTextAlignmentCenter;
}

#pragma mark - Lazy
- (NSTimer*)timer {
    if (!_timer) {
        
        _timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(sendRealLocationInfoToSocket) userInfo:nil repeats:YES];
        //暂停
        [_timer setFireDate:[NSDate distantFuture]];
        
    }
    return _timer;
}

-(SYDOutOfTheCar *)outCarView{
    if (!_outCarView) {
        _outCarView = [[SYDOutOfTheCar alloc]init];
        _outCarView.backgroundColor = CONTENT_BG_COLOR;
    }
    return _outCarView;
}

-(SYDDownwindOrderView *)downWindowOrderView{
    if (!_downWindowOrderView) {
        if ((iphone4) || (iPhone5_SE)) {
            _downWindowOrderView.constraintLength.constant = 20;
            _downWindowOrderView.breakContraintHeight.constant = 20;
            _downWindowOrderView.confirmConstraintHeight.constant = 20;
            _downWindowOrderView = [[SYDDownwindOrderView alloc]initWithFrame:CGRectMake(self.view.centerX - 155,74, 310, 385)];
        }else{
            _downWindowOrderView = [[SYDDownwindOrderView alloc]initWithFrame:CGRectMake(self.view.centerX - 165,94, 330, 400)];
        }
        [self orderFeedBack];
    }
    return _downWindowOrderView;
}

- (UIView *)maskView{
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:SCREEN_RECT];
        _maskView.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.7];
    }
    return _maskView;
}
-(statModel *)statModel{
    if (!_statModel) {
        _statModel = [[statModel alloc]init];
    }
    return _statModel;
}
-(NSDictionary *)message{
    if (!_message) {
        _message = [NSDictionary dictionary];
    }
    return _message;
}
-(SendsingleModel *)sendsingleModel{
    if (!_sendsingleModel) {
        _sendsingleModel = [[SendsingleModel alloc]init];
    }
    return _sendsingleModel;
}
@end
